﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mimoza.Common;
using Mimoza.Transport;

namespace Mimoza.DBLayer.Transport
{
    public class DBContainersCustomRequest
    {
        public enum CustomOperationType
        {
            None,
            GetContainer,
            GetChildsContainer,
            GetHosts,
            GetPolicies
        }

        public DBContainersCustomRequest()
        {
        }

        public DBContainersCustomRequest(CustomOperationType operationType)
        {
            Init(operationType, null);
        }

        public DBContainersCustomRequest(CustomOperationType operationType,
            string argument1)
        {
            Init(operationType, argument1);
        }

        void Init(CustomOperationType operationType, string argument1)
        {
            OperationType = operationType;
            Argument1 = argument1;
        }

        public CustomOperationType OperationType = CustomOperationType.None;
        public string Argument1 = null;
    }

    public class DBContainersTranferRequest :
        TransferObjectGeneric<DBContainersTranferRequest, RepositoryReply<ContainerRecord>>
    {
        public DBContainersTranferRequest()
        {
        }

        public DBContainersTranferRequest(Operation oper, ContainerRecord record)
        {
            Request.Operation = oper;
            Request.Object = record;
        }

        public DBContainersTranferRequest(DBContainersCustomRequest customReq)
        {
            Request.Operation = Operation.Custom;
            Request.CustomRequest = customReq;
        }

        override public RepositoryReply<ContainerRecord> ProcessRequest()
        {
            return Request.Process(Connection, Repository) as RepositoryReply<ContainerRecord>;
        }

        public RepositoryRequest<
            ContainerRecord, 
            ServerRepository<ContainerRecord, DBContainersCustomRequest, IDBContainerRepository>,
            DBContainersCustomRequest, 
            IDBContainerRepository> Request = new RepositoryRequest<
                ContainerRecord,
                ServerRepository<ContainerRecord, DBContainersCustomRequest, IDBContainerRepository>, 
                DBContainersCustomRequest, 
                IDBContainerRepository>();

        public static ServerRepository<ContainerRecord, DBContainersCustomRequest, IDBContainerRepository> Repository = null;
    }
}
